package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2023/9/6 09:51
 * @apiNote
 */

public class Test00045Jump {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 3, 1, 1, 4};
        int count = jump(nums);
        System.out.println(count);
    }


    public static int jump(int[] nums) {
        int n = nums.length;
        int i = n - 1;
        int count = 0;
        while (i >= 0) {
            int size = i;
            for (int j = i; j > 0; j--) {
                if (nums[j - 1] >= i - j) {
                    size = Math.min(size, j - 1);
                }
            }
            count++;
            i = size;
        }
        return count;
    }
}
